package com.imageim.yimirror.ui.adapter.tryCloth;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;

import com.imageim.yimirror.R;
import com.imageim.yimirror.base.BaseApplication;
import com.imageim.yimirror.bean.dailyPhoto.PhotoBgBean;
import com.imageim.yimirror.common.ui.GlideUtils;
import com.imageim.yimirror.common.util.LogUtil;
import com.makeramen.roundedimageview.RoundedImageView;

import org.byteam.superadapter.IMulItemViewType;
import org.byteam.superadapter.SuperAdapter;
import org.byteam.superadapter.SuperViewHolder;

import java.util.List;

/**
 * 试穿留影替换的背景列表
 * Created by Bruce.Zhou on 2018/11/22 11:36.
 * Email: 907160968@qq.com
 */
public class ChangePhotoBgListAdapter extends SuperAdapter<PhotoBgBean> {
    private int red = Color.parseColor(BaseApplication.getContext().getString(R.string.border_color));

    //    private Map<Integer, WeakReference<Bitmap>> bgMap;
    private String[] titles = {"原图", "圣诞礼品屋", "冰雪圣诞", "夜半街市", "彩虹墙", "暮色街角", "粉红房子", "街头涂鸦", "模拟星空",
            "星球表面", "水上板桥", "wall", "wall", "wall", "wall", "wall",
            "wall", "wall", "wall", "wall", "wall"};

    public ChangePhotoBgListAdapter(Context context, List<PhotoBgBean> items, int layoutResId) {
        super(context, items, layoutResId);
        //        bgMap = new HashMap<>();
    }

    public ChangePhotoBgListAdapter(Context context, List<PhotoBgBean> items, IMulItemViewType<PhotoBgBean> mulItemViewType) {
        super(context, items, mulItemViewType);
    }

    @Override
    public void onBind(SuperViewHolder holder, int viewType, int layoutPosition, PhotoBgBean item) {
        LogUtil.d("data", "bind data" + layoutPosition);
        RoundedImageView ivPhoto = holder.findViewById(R.id.iv_photo);
        if (item.getOriginalBitmap() != null) {
            ivPhoto.setImageBitmap(item.getOriginalBitmap());
        } else if (!TextUtils.isEmpty(item.getOriginalUrl())) {
            GlideUtils.display(ivPhoto, item.getOriginalUrl());
        } else {
            ivPhoto.setImageResource(item.getSmallResourceId());
        }
        holder.setText(R.id.tv_title, titles[layoutPosition]);

        if (item.isSelected()) {
            ivPhoto.setBorderColor(red);
            //            holder.setVisibility(R.id.select_view, View.VISIBLE);
        } else {
            ivPhoto.setBorderColor(Color.TRANSPARENT);
            //            holder.setVisibility(R.id.select_view, View.GONE);
        }
    }

    public void select(int position) {
        for (int i = 0; i < getData().size(); i++) {
            if (i != position) {
                getData().get(i).setSelected(false);
            } else {
                getData().get(i).setSelected(true);
            }
        }
        notifyDataSetChanged();
    }

    public String getTitle(int position) {
        if (position >= 0 && position < titles.length) {
            return titles[position];
        }
        return "未知背景";
    }


}
